using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using MallSystembackend.Api.Model;
using MallSystembackend.Api.Repository;
using System.Linq;
namespace MallSystembackend.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class MerchantAttentionController : ControllerBase
    {
        public IRepository<MerchantAttention> _merchantAttention;
        public readonly IConfiguration _configuration;

        public MerchantAttentionController(IRepository<MerchantAttention> merchantAttention,
        IConfiguration configuration
        )
        {
            _configuration = configuration;
            _merchantAttention = merchantAttention;
        }
        //用户添加关注
        [HttpPost]
        public ActionResult AddMerchantAttention(ParamMerchantAttention model)
        {

            var merany = _merchantAttention.Table;
            var merone = merany.Where(x => x.UsersId == model.UsersId &&
              x.MerchantAttentionId == model.MerchantAttentionId).FirstOrDefault();
            System.Console.WriteLine(merone);
            System.Console.WriteLine(1111);
            if (merone != null)
            {
                return Ok(new
                {
                    Code = 1002,
                    Data = model,
                    Msg = "你已关注过"
                });

            }
            else
            {
                var merchantAttention = new MerchantAttention
                {
                    UsersId = model.UsersId,
                    MerchantAttentionId = model.MerchantAttentionId
                };
                _merchantAttention.Insert(merchantAttention);
                return Ok(new
                {
                    Code = 1000,
                    Data = merchantAttention,
                    Msg = "添加成功"
                });
            }


        }
    }
}